package cn.ccbfund.demo.controller;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;

import cn.ccbfund.common.validate.ValidateConfig;
import cn.ccbfund.common.web.BaseController;
import cn.ccbfund.common.web.R;
import cn.ccbfund.demo.model.DemoMO;
import cn.ccbfund.demo.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags="示例")
@RestController
@RequestMapping("/demo")
public class DemoController extends BaseController {

    @Autowired 
    private DemoService demoService;
    
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public Page<DemoMO> page(Integer currentPage, Integer pageSize, String code, String name) {
        return demoService.queryDemoMO(currentPage, pageSize, code, name);
    }

    @ApiOperation(value = "新增示例")
    @PostMapping
    public R<Boolean> insert(@RequestBody @Validated(ValidateConfig.ADD.class)DemoMO mo) {
        return new R<>(demoService.insertDemoMO(mo));
    }

    @ApiOperation(value = "修改示例")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated(ValidateConfig.UPDATE.class) DemoMO mo) {
        return new R<>(demoService.updateDemoMOById(mo));
    }
    
    @ApiOperation(value = "删除示例")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable String id) {
        return new R<>(demoService.deleteDemoMOById(id));
    } 
}
